<?php
/**
 * 办卡日志管理类
 *
 * @auther 大耳牛
 * 2016-12-31
 **/
namespace Xijie\Model;
use Think\Model;
class RoomcardModel extends Model{
	//定义表名称
	protected $tableName = 'room_card';
	
	/**
	 * 获取房卡日志列表总数
	 *
	 **/
	public function getRoomCardCount($where){
		return $this->alias('card')->where($where)->count();
	}
	
	/**
	 * 获取房卡日志列表
	 *
	 **/
	public function getRoomCardList($page, $where){
		$list = $this->alias('card')
					//->join('left join momoda_room as room on card.room_number = room.room_number')
					->join('left join momoda_member as member on card.member_id = member.member_id')
					->field('card.*, member.member_nick')
					->where($where)
					->order('card.id desc')
					->page($page, C('PAGE_SIZE'))
					->select();
		return $list;
	}
	
	/**
	 * 添加房卡日志
	 **/
	public function addRoomCardnfo($data){
		return $this->data($data)->add();
	}
	
	/**
	 * 根据办卡日志ID获取办卡基础信息
	 * @param int $logId
	 **/
	public function getRoomCarInfoByLogId($logId){
		return $this->alias('roomcard')
					->join('left join momoda_member as member on roomcard.member_id = member.member_id')
					->field('roomcard.*, member.member_nick,member.member_phone')
					->where(array('roomcard.id' => $logId))
					->find();
	}
	
	/**
	 * 根据办卡日志ID修改办卡信息
	 * @param int $logId
	 **/
	public function editRoomCardInfoByLogId($logId){
		return $this->where(array('id' => $logId))->setField('is_back', 1);
	}
	
	/**
	 * 获取制卡记录
	 **/
	public function getRoomCardInfoByWhere($where){
		return $this->where($where)->find();
	}
	
	/**
	 * 修改数据
	 **/
	public function editRoomCardInfoByLogIds($data, $logId){
		return $this->where(array('id' => $logId))->setField($data);
	}
}